# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=sfml
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.0
pkgrel=1
pkgdesc="A simple, fast, cross-platform, and object-oriented multimedia API (mingw-w64)"
arch=('any')
url="http://www.sfml-dev.org/"
license=("zlib")
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
depends=("${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-openal")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "unzip")
source=(http://www.sfml-dev.org/files/SFML-${pkgver}-sources.zip
        mingw-w64-msys2.patch)
sha256sums=('868a1a1e43a7ee40c1a90efcbcea061b6f0a6ed129075d9a8f19c8c69e644b0f'
            '99e614b91e2631737ff5b8c964530611c725db1964519f8d693875b0dda6dc43')
noextract=(SFML-${pkgver}-sources.zip)

prepare() {
  unzip SFML-${pkgver}-sources.zip
  cd ${srcdir}/SFML-${pkgver}
  patch -p1 -i ${srcdir}/mingw-w64-msys2.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -r build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DSFML_BUILD_EXAMPLES=1 \
    -DSFML_BUILD_DOC=1 \
    -DSFML_INSTALL_PKGCONFIG_FILES=ON \
    ../SFML-${pkgver}

  make
  make doc
}

package() {
  cd build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 "${pkgdir}${MINGW_PREFIX}/share/SFML/cmake/Modules/FindSFML.cmake" "${pkgdir}${MINGW_PREFIX}/share/cmake-3.2/Modules/FindSFML.cmake"
  install -Dm644 ${srcdir}/SFML-${pkgver}/license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
